home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-1.iso / games / nerak2.zip / MERCHANT.SCR < prev    next >
Text File  |  1995-09-24  |  13KB  |  396 lines

  1. !
  2. ! Default merchant script..
  3. !
  4. ! (c) DC Software, 1989-1995
  5. !
  6.  
  7. !------------------------------------------------------------------------!
  8. :@TALK ! Talk to the character !
  9. !------------------------------------------------------------------------!
  10.  
  11.   if player.hp = 0 then
  12.     writeln( player.name, " is dead!" );
  13.     STOP;
  14.   endif;
  15.  
  16.   if npc.picture >= 0 then
  17.     viewpcx(npc);
  18.   endif;
  19.  
  20.   loadtext( npc.text ); ! Get the NPC's text block !
  21.   loadvfl( npc.voice ); ! Get the NPC's voice block !
  22. ! First, say hello.. !
  23.   if NPC.V0 > 0 then
  24.     writeln( "Hello ", player.name, ". What brings you back?" );
  25.   else
  26.     writeln( "Welcome to ", npc.name, ". How may I help you?" );
  27.   endif;
  28.  
  29. ! Now, set some variables..
  30.   NPC.V0 = 1; ! From know on, remember we've been here
  31.   L1 = 0;     ! No items have been SOLD to the player
  32.   L2 = 0;     ! No items have been BOUGHT from the player
  33.   L5 = 0;     ! No items have been ANALYZED for the player
  34.  
  35. ! Then start a loop and show a menu..
  36. :LOOP
  37.   L3 = select( "Buy", "Sell", "Identify", "Talk", "Bye" );
  38.   on L3 goto BUY, SELL, GETINFO, CHAT;
  39.  
  40. ! ESCape and BYE get's us out of here..
  41. :CSTOP
  42.   if L1 = 0 and L2 = 0 and L5 = 0 then
  43.     writeln( "Next time buy something!" );
  44.   else
  45.     writeln( "It's been a pleasure doing business with you!" );
  46.   endif;
  47.   stats(-1); ! Refresh Statistics !
  48.   goto XSTOP;
  49.  
  50. !-------------------------------------------------!
  51. ! Player want's to buy something from us..        !
  52. !-------------------------------------------------!
  53. :BUY
  54.   L3 = select$( NPC );
  55.   if L3 < 0 goto LOOP;
  56.  
  57.   if NPC.BP.VALUE >= GROUP.GOLD then 
  58.     writeln( "You don't have enough money!");
  59.     voice( "Broke" );
  60.   else
  61.     if npc.bp.type = FOOD and npc.bp.class = NONE then
  62.       L10 = 255 - group.food; ! Max food we can carry !
  63.       if L10 < npc.bp.count then
  64.         L11 = npc.bp.count - L10;
  65.         writeln( "{You have to carry ", L11, " in your backpack}" );
  66.         inc( group.food, L10 );
  67.         copy( npc.bp, player, L11 ); ! Put L11 foods in the backpack !
  68.         if failure then
  69.           L12 = failure - 1;
  70.           writeln( "{The excess merchandize is placed on the floor!}" );
  71.           drop( npc.bp, -L12 ); ! Negative count means "drop a copy" !
  72.         endif;
  73.       else
  74.         inc( group.food, npc.bp.count );
  75.         writeln( "You add the food to the party's pool.." );
  76.       endif;
  77.     else
  78.       L12 = npc.bp.count;
  79.       copy( NPC.BP, PLAYER );
  80.       if failure then
  81.         ! Value of failure is # that DID NOT get moved (+1) !
  82.         L11 = failure - 1;
  83.         if L12 > 1 then
  84.           if L11 < L12 then
  85.             writeln( "You can only carry {", L11, "}. I'll put the rest on one side" );
  86.           else
  87.             writeln( "You cannot carry them. I'll put them on one side." );
  88.           endif;
  89.         else
  90.           write( "You can't carry it. I'll put it on one side." );
  91.         endif;
  92.         ! First we put the item UNDER the player !
  93.         L13 = player.x;
  94.         L14 = player.y;
  95.         L15 = npc.y - player.y;
  96.         L16 = npc.x - player.x;
  97.         ! Then we try in FRONT of the player, if possible !
  98.         if L16 = 0 and abs(L15) > 1 then
  99.           ! There is at least one space between player and npc, vertical !
  100.           L14 = player.y + sgn(L15);
  101.         elsif L15 = 0 and abs(L16) > 1 then
  102.           ! There is at least one space between player and npc, horizontal !
  103.           L13 = player.x + sgn(L16);
  104.         endif;
  105.         drop( npc.bp, -L11, L13, L14 ); ! Put L11 items (- to COPY, not DROP) !
  106.       endif;
  107.     endif;
  108.     dec ( GROUP.GOLD, NPC.BP.VALUE );
  109.     inc ( L1 );                     ! Sold 1 item to the PLAYER !
  110.     writeln( "SOLD: ", NPC.BP.COUNT, " ", NPC.BP.NAME, " for ", $NPC.BP.VALUE );
  111.     voice( "Sold" );
  112.   endif;
  113.   goto BUY;
  114.  
  115. !
  116. ! Player want's to sell something to us..
  117. !
  118. :SELL
  119.   L3 = select$2( PLAYER, matching ); ! Shows only thing's that I might want to buy  !
  120.   if L3 < 0 then
  121.     if L3 = -2 then   ! No items in the player's backpack !
  122.       if L2 > 0 then
  123.         writeln( "You have no more items to sell." );
  124.         voice( "NonLeft" );
  125.       else
  126.         writeln( "You have no items to sell." );
  127.         voice( "NoItems" );
  128.       endif;
  129.     endif;
  130.     if L3 = -3 then   ! No items of the type(s) I sell in the backpack !
  131.       if L2 > 0 then
  132.         writeln( "You have no more items that I would like to buy." );
  133.         voice( "NonLeft" );
  134.       else
  135.         writeln( "You have no items that I would like to buy." );
  136.         voice( "NoItems" );
  137.       endif;
  138.     endif;
  139.     goto LOOP;
  140.   endif;
  141.  
  142. ! Buy an item at half price (it's used) !
  143.   if player.bp.count > 1 then
  144.     L10 = getnum( "Sell how many?", 0, player.bp.count );
  145.   else
  146.     L10 = 1;
  147.   endif;
  148.   if L10 > 0 then
  149.     if player.bp.type = FOOD and player.bp.class = POISON then
  150.       writeln( "Sorry. This food is poisoned.  Anything else?" );
  151.       goto SELL;
  152.     endif;
  153.     L4 = (PLAYER.BP.VALUE+1) / 2;   ! Price paid for the item.
  154.     if L10 > 1 then
  155.       writeln( "Here is ", $L4, " for each of your ", L10, " ", PLAYER.BP.NAME, "s" );
  156.     else
  157.       writeln( "Here is ", $L4, " for your ", PLAYER.BP.NAME );
  158.     endif;
  159.     voice( "Bought" );
  160.     inc( group.gold, L4*L10 );     ! Pay the player for the items
  161.     inc( L2 );                     ! Bought 1 item from the player !
  162.  
  163.     ! Now, see if we have an exact or approximate match
  164.     for L11 = 0 to 15 do
  165.       setbp( npc, L11 );
  166.       if npc.bp.count > 0               and
  167.          npc.bp.name  = player.bp.name  and
  168.          npc.bp.type  = player.bp.type  and
  169.          npc.bp.class = player.bp.class and
  170.          npc.bp.value = player.bp.value goto REMOVEIT;
  171.     endfor;
  172.     ! Merchant does not have an identical item, so we will copy 1 (one)
  173.     ! item into the backpack for later resale
  174.     !
  175.     ! Note: The assumption is that the 'value' field contains the
  176.     ! UNIT value.  If the player had 20 items, we paid 20 x value, so
  177.     ! we keep 1 copy and sell each for 'value' amount.
  178.     copy( player.bp, npc, 1 );
  179.  
  180.     :REMOVEIT
  181.     if L10 < player.bp.count then
  182.       dec( player.bp.count, L10 ); ! Remove the items we sold
  183.     else
  184.       player.bp.count = 0;         ! Zap the items
  185.     endif;
  186.   else
  187.     writeln( "Maybe another item? <ESC> for go back" );
  188.   endif;
  189.  
  190.   goto SELL;
  191.  
  192. !
  193. ! Player want's to know about some of the items he has..
  194. !
  195. :GETINFO
  196.   writeln( "Let me see.. What do you wish to identify?" );
  197.   L3 = select$2( PLAYER, matching ); ! Item's I know about !
  198.   if L3 < 0 then
  199.     if L3 = -2 then   ! No items in the player's backpack !
  200.       if L2 > 0 then
  201.         writeln( "You have no more items!" );
  202.         voice( "NonLeft" );
  203.       else
  204.         writeln( "Your backpack is empty!" );
  205.         voice( "NoItems" );
  206.       endif;
  207.     endif;
  208.     if L3 = -3 then   ! No items of the type(s) I sell in the backpack !
  209.       if L2 > 0 then
  210.         writeln( "There are no other items I can identify!" );
  211.         voice( "NonLeft" );
  212.       else
  213.         writeln( "There are no items that I can identify!" );
  214.         voice( "NoItems" );
  215.       endif;
  216.     endif;
  217.     goto LOOP;
  218.   endif;
  219.  
  220. ! Identify the selected item
  221.   L4 = (player.bp.value+7) / 8;
  222.   writeln( "The fee is ", $L4, ". Do you pay it?" );
  223.   L11 = select( "Yes", "No" );
  224.   if L11 = 0 then ! Yes !
  225.     if group.gold < L4 then
  226.       writeln( "You don't have enough money!" );
  227.       voice( "Broke" );
  228.       goto LOOP;
  229.     endif;
  230.     gosub DESCRIBE;
  231.     writeln( "What name do you want to give it? <ESC>=none" );
  232.     L3 = getstr();
  233.     if L3 = -2 then ! -1 = <ESC>, -2 = Any string not in the list (No List) !
  234.       player.bp.name = S0;
  235.     else
  236.       writeln( "ok" );
  237.     endif;
  238.     dec( group.gold, L4 );
  239.   else
  240.     writeln( "Maybe another item? <ESC> to go back" );
  241.   endif;
  242.  
  243.   goto GETINFO;
  244.  
  245. !-------------------------------------------------------------------!
  246. ! Describe an item (player's BP)                                    !
  247. !-------------------------------------------------------------------!
  248. :DESCRIBE
  249.  
  250.   if player.bp.count < 0 then
  251.     writeln( "I don't know what you're talking about" );
  252.     return;
  253.   endif;
  254.  
  255.   write( "Name: ", player.bp.name, ", Type: ", player.bp.type );
  256.  
  257.   if player.bp.type = FOOD or player.bp.type = POTION  then
  258.     if player.bp.class then
  259.       write( ", Class: ", player.bp.class );
  260.       if player.bp.class <> CURE then
  261.         write( ", Units: ", player.bp.units );
  262.       endif;
  263.     else
  264.       write( ", it has no special properties" );
  265.     endif;
  266.   elsif player.bp.type = WEAPON then
  267.     write( ", Class: ", player.bp.class, 
  268.            ", Hands: ", player.bp.hands, 
  269.            ", Range: ", player.bp.range, 
  270.            ", Damage: ", player.bp.damage );
  271.     if player.bp.ammoneeded then
  272.       write( ", Needs ammo type: ", player.bp.ammo_type );
  273.     endif;
  274.   elsif player.bp.type = AMMO then
  275.     write( ", Ammo Type: ", player.bp.ammotype );
  276.     if player.bp.traptype then
  277.       write( ", Poisoned" );
  278.     endif;
  279.     if player.bp.damage then
  280.       write( ", Extra Damage: ", player.bp.damage );
  281.     endif;
  282.   elsif player.bp.type = ARMOR or player.bp.type = SHIELD then
  283.     write( ", Armor Class: ", player.bp.ac );
  284.     if player.bp.cursed then
  285.       write( " Cursed!" );
  286.     endif;
  287.   elsif player.bp.type = AMULET or player.bp.type = RING or player.bp.type = GEMS then
  288.     if player.bp.class then
  289.       write( ", Class: ", player.bp.class );
  290.       write( ", Charges: ", player.bp.charges );
  291.       if player.bp.class <> CURE then
  292.         write( ", Units: ", player.bp.units );
  293.         if player.bp.permanent then
  294.           write( ", Permanent!" );
  295.         else
  296.           write( ", Temporary" );
  297.         endif;
  298.       endif;
  299.       if player.bp.cursed then
  300.         write( ", Cursed!" );
  301.       endif;
  302.     endif;
  303.   elsif player.bp.type = SCROLL then
  304.     write( ", Class: ", player.bp.class );
  305.   elsif player.bp.type = STAFF then
  306.     write( ", Class: ", player.bp.class, ", Charges: ", player.bp.charges );
  307.   elsif player.bp.type = CHEST then
  308.     if player.bp.locktype then
  309.       write( ", Locked!" );
  310.       if player.bp.traptype = 0 then
  311.         write( ", no traps" );
  312.       elsif player.bp.traptype = 1 then
  313.         write( ", poison trap" );
  314.       else
  315.         write( ", bomb damage: ", player.bp.traptype );
  316.       endif;
  317.     endif;
  318. ! elsif player.bp.type = KEYS     then
  319. !   nothing special about it
  320. ! elsif player.bp.type = BOOK     then
  321. !   nothing special about it
  322. ! elsif player.bp.type = GOLDSACK then
  323. !   nothing special about it
  324. ! elsif player.bp.type = TORCH    then
  325. !   nothing special about it
  326. ! elsif player.bp.type = LANTERN  then
  327. !   nothing special about it
  328. ! elsif player.bp.type = ROPE     then
  329. !   nothing special about it
  330. ! elsif player.bp.type = HOOKS    then
  331. !   nothing special about it
  332. ! elsif player.bp.type = MIRROR   then
  333. !   nothing special about it
  334. ! elsif player.bp.type = SIGN     then
  335. !   nothing special about it
  336.   elsif player.bp.type = VEHICLE then
  337.     write( ", Class: ", player.bp.class );
  338. ! else
  339. !   user defined type?
  340.   endif;
  341.   if player.bp.weight > 1 and player.bp.weight < 256 then
  342.     write( ", Weight: ", player.bp.weight );
  343.   endif;
  344.   writeln( "." );
  345.   return;
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353. !
  354. ! Handle conversation..
  355. !
  356. :CHAT
  357.   writeln( "What would you like to talk about?" );
  358.  
  359. :CHAT1
  360.   L3 = getstr("Name","Buy","Sell","Credit","Job","Bye");
  361.   if L3 = -1 then 
  362.     writeln( "Ok." );
  363.     goto LOOP; ! Pressed ESCape !
  364.   endif;
  365.  
  366. ! First, see if the keyword typed is in the character's text block !
  367.   if dotext( S0 ) then
  368.     if L3 = 5 goto XSTOP;
  369.     goto CHAT1;
  370.   endif;
  371.  
  372. ! It didn't, so try the predefined ones..
  373.   on L3 goto CNAME, BUY, SELL, CCREDIT, CJOB, CSTOP;
  374.  
  375. ! Nope, try a 'DEFAULT' line
  376.   if not dotext( "DEFAULT" ) then
  377.     writeln( "I don't know anything about that!" );
  378.   endif;
  379.   goto CHAT1;
  380.  
  381. :CNAME   writeln( "My name is ", NPC.name, "." ); GOTO CHAT1;
  382. :CCREDIT writeln( "No credit sales, sorry!"    ); GOTO CHAT1;
  383. :CJOB    writeln( "You can {buy} and {sell} items here." ); GOTO CHAT1;
  384.  
  385. ! Feel free to expand on this list.. !
  386.  
  387. !-----------------------------------------------------------------!
  388. ! All STOPs now lead here so the screen can be restored if needed !
  389. !-----------------------------------------------------------------!
  390. :XSTOP
  391.   if npc.picture >= 0 then
  392.     paint(window); ! Assumes the picture fits in the window !
  393.   endif;
  394.   STOP;
  395.  
  396.